package web;

import entity.SellList;
import org.apache.commons.beanutils.BeanUtils;
import service.SellListService;
import service.impl.SellListServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/AddSellListServlet")
public class AddSellListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        SellList sellList = new SellList();
        try {
            BeanUtils.populate(sellList,request.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        SellListService sellService = new SellListServiceImpl();
        sellService.addSellList(sellList);
        response.sendRedirect(request.getContextPath() + "/SellListServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
